﻿using System;
using System.Collections.Generic;
using Terraria.Achievements;

namespace Terraria.GameContent.Achievements
{
	// Token: 0x0200046C RID: 1132
	public class ProgressionEventCondition : AchievementCondition
	{
		// Token: 0x06002679 RID: 9849 RVA: 0x0001AC3C File Offset: 0x00018E3C
		private ProgressionEventCondition(int eventID) : base("PROGRESSION_EVENT_" + eventID)
		{
			this._eventIDs = new int[]
			{
				eventID
			};
			ProgressionEventCondition.ListenForPickup(this);
		}

		// Token: 0x0600267A RID: 9850 RVA: 0x0001AC6A File Offset: 0x00018E6A
		private ProgressionEventCondition(int[] eventIDs) : base("PROGRESSION_EVENT_" + eventIDs[0])
		{
			this._eventIDs = eventIDs;
			ProgressionEventCondition.ListenForPickup(this);
		}

		// Token: 0x0600267B RID: 9851 RVA: 0x00491CCC File Offset: 0x0048FECC
		private static void ListenForPickup(ProgressionEventCondition condition)
		{
			if (!ProgressionEventCondition._isListenerHooked)
			{
				AchievementsHelper.OnProgressionEvent += ProgressionEventCondition.ProgressionEventListener;
				ProgressionEventCondition._isListenerHooked = true;
			}
			for (int i = 0; i < condition._eventIDs.Length; i++)
			{
				if (!ProgressionEventCondition._listeners.ContainsKey(condition._eventIDs[i]))
				{
					ProgressionEventCondition._listeners[condition._eventIDs[i]] = new List<ProgressionEventCondition>();
				}
				ProgressionEventCondition._listeners[condition._eventIDs[i]].Add(condition);
			}
		}

		// Token: 0x0600267C RID: 9852 RVA: 0x00491D50 File Offset: 0x0048FF50
		private static void ProgressionEventListener(int eventID)
		{
			if (ProgressionEventCondition._listeners.ContainsKey(eventID))
			{
				List<ProgressionEventCondition> list = ProgressionEventCondition._listeners[eventID];
				foreach (ProgressionEventCondition progressionEventCondition in list)
				{
					progressionEventCondition.Complete();
				}
			}
		}

		// Token: 0x0600267D RID: 9853 RVA: 0x0001AC91 File Offset: 0x00018E91
		public static ProgressionEventCondition Create(params int[] eventIDs)
		{
			return new ProgressionEventCondition(eventIDs);
		}

		// Token: 0x0600267E RID: 9854 RVA: 0x0001AC99 File Offset: 0x00018E99
		public static ProgressionEventCondition Create(int eventID)
		{
			return new ProgressionEventCondition(eventID);
		}

		// Token: 0x0600267F RID: 9855 RVA: 0x00491DB8 File Offset: 0x0048FFB8
		public static ProgressionEventCondition[] CreateMany(params int[] eventIDs)
		{
			ProgressionEventCondition[] array = new ProgressionEventCondition[eventIDs.Length];
			for (int i = 0; i < eventIDs.Length; i++)
			{
				array[i] = new ProgressionEventCondition(eventIDs[i]);
			}
			return array;
		}

		// Token: 0x040041A9 RID: 16809
		private const string Identifier = "PROGRESSION_EVENT";

		// Token: 0x040041AA RID: 16810
		private static Dictionary<int, List<ProgressionEventCondition>> _listeners = new Dictionary<int, List<ProgressionEventCondition>>();

		// Token: 0x040041AB RID: 16811
		private static bool _isListenerHooked = false;

		// Token: 0x040041AC RID: 16812
		private int[] _eventIDs;
	}
}
